package com.qf.controller;

import com.alibaba.fastjson.parser.deserializer.AbstractDateDeserializer;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.entity.AddressEntity;
import com.qf.result.Result;
import com.qf.service.AddressService;
import com.sun.javafx.iio.ImageFormatDescription;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.management.Query;
import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 *
 *
 * @author liuzishuo
 * @email sunlightcs@gmail.com
 * @date 2021-07-20 19:53:33
 */
@RestController
@RequestMapping("/address")
public class AddressController {
    @Autowired
    private AddressService addressService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public Result list(@RequestParam Map<String, Object> params) {

        return Result.success();

    }
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public AddressEntity info(@PathVariable("id") Integer id){
        AddressEntity entity = addressService.getById(id);
        return entity;
    }
    /**
     * 保存
     */
    @RequestMapping("/save")
    public Result save(@RequestBody AddressEntity address){
		addressService.save(address);

        return Result.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public Result update(@RequestBody AddressEntity address){
		addressService.updateById(address);

        return Result.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public Result delete(@RequestBody Integer[] ids){
		addressService.removeByIds(Arrays.asList(ids));

        return Result.success();
    }

    @RequestMapping("getAddressListByUid")
   public List<AddressEntity> getAddressListByUid(@RequestParam(value = "uid") Integer uid){
        QueryWrapper<AddressEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("uid",uid);
        List<AddressEntity> addressEntityList = addressService.list(wrapper);
        return addressEntityList;

    }

}
